package cn.power.win.win_power.fragment;

import android.app.ActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.power.win.win_power.R;
import cn.power.win.win_power.acitivity.ContractActivity;
import cn.power.win.win_power.acitivity.GuideActivity;
import me.jessyan.autosize.internal.CustomAdapt;

import static android.content.Context.ACTIVITY_SERVICE;
/*
*   侧滑菜单栏
*
* */

public class LeftFragment extends Fragment implements View.OnClickListener , CustomAdapt {
    private DrawerLayout drawer_layout;
    private FragmentManager fManager;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fg_left, container, false);
  /*
  * 点击事件
  * */
        view.findViewById(R.id.ll_help).setOnClickListener(this);
        view.findViewById(R.id.ll_contract).setOnClickListener(this);
        view.findViewById(R.id.ll_exite).setOnClickListener(this);
        fManager = getActivity().getSupportFragmentManager();
        return view;
    }

    //暴露给Activity，用于传入DrawerLayout，因为点击后想关掉DrawerLayout
    public void setDrawerLayout(DrawerLayout drawer_layout){
        this.drawer_layout = drawer_layout;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_help:
                //Toast.makeText(getActivity(), "帮助", Toast.LENGTH_SHORT).show();
                //跳转到帮助文档
                 startActivity(new Intent(getActivity(),GuideActivity.class));
                //关闭侧滑菜单
                drawer_layout.closeDrawer(Gravity.START);
                break;
            case R.id.ll_contract:
                //跳转到联系界面
               // Toast.makeText(getActivity(), "联系我们", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(getActivity(),ContractActivity.class));
                drawer_layout.closeDrawer(Gravity.START);
                break;
            case R.id.ll_exite:
               // Toast.makeText(getActivity(), "退出", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                startActivity(intent);
                System.exit(0);

                // 关闭侧滑
                drawer_layout.closeDrawer(Gravity.START);
                break;
        }
    }

    @Override
    public boolean isBaseOnWidth() {
        return true;
    }

    @Override
    public float getSizeInDp() {
        return 670;
    }
}
